package net.kazed.nextaction.database.serialize;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

/**
 * Encode/decode XML values with UrlEncoder.
 * @author Koert Zeilstra
 */
public class UrlXmlEncoder implements XmlEncoder {

    @Override
    public String decode(String value) {
        String result = null;
        try {
            result = URLDecoder.decode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("invalid encoding", e);
        }
        return result;
    }

    @Override
    public String encode(String value) {
        String result = null;
        try {
            result = URLEncoder.encode(value, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("invalid encoding", e);
        }
        return result;
    }

}
